﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using System.Net.Sockets;
using System.Net;

namespace EP2_LoginServer
{
    public static class Config
    {

        public static IPAddress LoginServerIP;
        public static int LoginServerPort,GameServerPort,GameServerChannels;
        public static string GameServerIP;
        

        public static void Read()
        {
            try
            {
                TextReader tr = new StreamReader("LoginServer.cfg");

                string line;
                while ((line = tr.ReadLine()) != null)
                {
                    if (line.Contains("#") || line.Length == 0)
                    {
                    }
                    else
                    {
                        string[] values = line.Split('=');
                        foreach (string v in values)
                        {
                            if (values[0] == "IP") LoginServerIP = IPAddress.Parse(values[1]);
                            if (values[0] == "PORT") LoginServerPort = Convert.ToInt32(values[1]);
                            if (values[0] == "SQL_HOST") mySQL.host = values[1];
                            if (values[0] == "SQL_DBASE") mySQL.database = values[1];
                            if (values[0] == "SQL_USER") mySQL.user = values[1];
                            if (values[0] == "SQL_PASSWORD") mySQL.password = values[1];
                            if (values[0] == "GS_IP") GameServerIP = values[1];
                            if (values[0] == "GS_PORT") GameServerPort = Convert.ToInt32(values[1]);
                            if (values[0] == "GS_CHANNELS") GameServerChannels = Convert.ToInt32(values[1]);

                        }

                    }
                }

                LogScreen.Info("Config file Loaded");
            }
            catch( Exception e)
            {
                LogScreen.Error("Config file Error : " + e);
            }

        }
    }
}
